package com.xinqi.modules.stats.score.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.CourseContentTypeEnum;
import com.xinqi.common.core.enums.TotalScoreTypeEnum;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.common.mybatis.utils.Pages;
import com.xinqi.common.mybatis.utils.Queries;
import com.xinqi.modules.course.clazz.client.ClassClient;
import com.xinqi.modules.course.clazz.client.ClassStudentClient;
import com.xinqi.modules.course.clazz.dto.rsp.ClassResultDTO;
import com.xinqi.modules.course.clazz.dto.rsp.ClassStudentResultDTO;
import com.xinqi.modules.course.course.client.RemoteCourseClient;
import com.xinqi.modules.course.course.dto.rsp.CourseResultDTO;
import com.xinqi.modules.stats.score.convert.CourseTotalScoreConfigConvert;
import com.xinqi.modules.stats.score.convert.CourseTotalScoreConvert;
import com.xinqi.modules.stats.score.convert.CourseTotalScoreTypeConvert;
import com.xinqi.modules.stats.score.domain.CourseTotalScoreEntity;
import com.xinqi.modules.stats.score.domain.CourseTotalScoreTypeEntity;
import com.xinqi.modules.stats.score.dto.req.*;
import com.xinqi.modules.stats.score.dto.rsp.*;
import com.xinqi.modules.stats.score.mapper.*;
import com.xinqi.modules.stats.score.service.CourseTotalScoreConfigService;
import com.xinqi.modules.stats.score.service.CourseTotalScoreTypeConfigService;
import com.xinqi.modules.stats.score.service.CourseTotalScoreTypeService;
import com.xinqi.modules.stats.utils.ExcelUtil;
import com.xinqi.modules.stats.utils.MathUtils;
import lombok.RequiredArgsConstructor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 总成绩各分类栏目等级制分值配置表服务层实现
 *
 * @author: dzy
 * @date: 2023/03/26
 */
@Service("courseTotalScoreTypeService")
@RequiredArgsConstructor
public class CourseTotalScoreTypeServiceImpl extends BaseServiceImpl<CourseTotalScoreTypeMapper, CourseTotalScoreTypeEntity> implements CourseTotalScoreTypeService {

    private final CourseTotalScoreConvert courseTotalScoreConvert;

    private final CourseTotalScoreConfigConvert courseTotalScoreConfigConvert;

    private final CourseTotalScoreTypeConvert courseTotalScoreTypeConvert;

    private final CourseTotalScoreMapper courseTotalScoreMapper;

    private final CourseTotalScoreConfigService courseTotalScoreConfigService;

    private final CourseTotalScoreTypeConfigService courseTotalScoreTypeConfigService;

    private final CourseTotalScoreStudentMapper courseTotalScoreStudentMapper;

    private final CourseTotalScoreContentSonMapper courseTotalScoreContentSonMapper;

    private final ClassClient classClient;

    private final ClassStudentClient classStudentClient;

    private final RemoteCourseClient remoteCourseClient;

    /**
     * 查询分类成绩的基础配置信息
     */
    @Override
    public CourseTotalScoreTypeResultDTO findCourseTotalScoreType(CourseTotalScoreTypeQueryDTO dto) {
        LambdaQueryWrapper<CourseTotalScoreTypeEntity> wrapper = Queries.lambda();
        wrapper.eq(CourseTotalScoreTypeEntity::getClassId, dto.getClassId());
        wrapper.eq(CourseTotalScoreTypeEntity::getType, dto.getType());
        return this.baseMapper.selectDtoOne(wrapper, courseTotalScoreTypeConvert::convert);
    }

    /**
     * 编辑分类成绩的基础配置信息
     */
    @Override
    public boolean setCourseTotalScoreType(CourseTotalScoreTypeCreateDTO dto) {
        CourseTotalScoreTypeQueryDTO queryDTO = new CourseTotalScoreTypeQueryDTO();
        queryDTO.setClassId(dto.getClassId());
        queryDTO.setType(dto.getType());
        CourseTotalScoreTypeResultDTO resultDTO = this.findCourseTotalScoreType(queryDTO);
        ClassResultDTO classResultDTO = classClient.findClass(dto.getClassId()).getData();
        if (resultDTO == null) {
            CourseTotalScoreTypeEntity entity = courseTotalScoreTypeConvert.create(dto);
            entity.setCourseId(classResultDTO.getCourseId());
            return this.save(entity);
        } else {
            resultDTO.setIsUserLevelShow(dto.getIsUserLevelShow());
            CourseTotalScoreTypeEntity entity = courseTotalScoreTypeConvert.create(resultDTO);
            return this.updateById(entity);
        }
    }

    /**
     * 老师 APP端各分类成绩查询
     */
    @Override
    @DS("slaver")
    public List<TotalScoreStudentListDTO> teacherTypeScore(CourseTotalScoreTypeQueryDTO dto) {
        List<TotalScoreStudentListDTO> list = courseTotalScoreMapper.teacherStudentTotalScoreList(dto);
        list.forEach(item -> {
            item.setStudentScore(MathUtils.stripTrailingZeros(item.getStudentScore(), 1));
            item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
        });
        return list;
    }

    /**
     * 老师 分类成绩查询 分页
     */
    @Override
    @DS("slaver")
    public PageInfo<TotalScoreStudentListDTO> teacherTypeScorePage(CourseTotalScoreTypeQueryDTO dto) {
        PageInfo<TotalScoreStudentListDTO> page =
            Pages.convert(courseTotalScoreMapper.teacherStudentTotalScorePage(Pages.page(dto), dto));
        page.getRows().forEach(item -> {
            item.setStudentScore(MathUtils.stripTrailingZeros(item.getStudentScore(), 1));
            item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
        });
        return page;
    }

    /**
     * 老师 APP端各分类成绩查询
     */
    @Override
    @DS("slaver")
    public CourseContentTotalScorePCResultDTO pcTeacherTypeScore(CourseTotalScoreStudentQueryDTO dto) {

        CourseContentTotalScorePCResultDTO resultDTO = new CourseContentTotalScorePCResultDTO();

        // 查询分表表头信息
        List<CourseContentTotalTipDTO> tipList = courseTotalScoreStudentMapper.studentTypeScoreTitle(dto);
        tipList.forEach(item -> {
            item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
            item.setAvgScore(MathUtils.stripTrailingZeros(item.getAvgScore(), 1));
        });
        resultDTO.setTipList(tipList);

        // 学生得分行转列
        CourseTotalScoreStudentRowsQueryDTO rowsQueryDTO = new CourseTotalScoreStudentRowsQueryDTO();
        rowsQueryDTO.setClassId(dto.getClassId());
        rowsQueryDTO.setType(dto.getType());
        rowsQueryDTO.setKeyWords(dto.getKeyWords());
        rowsQueryDTO.setGroupId(dto.getGroupId());
        rowsQueryDTO.setList(tipList);
        List<Map<String, Object>> studentList = courseTotalScoreStudentMapper.studentTypeScoreList(rowsQueryDTO);
        resultDTO.setStudentList(studentList);

        return resultDTO;
    }

    /**
     * 老师端各分类成绩详情查询
     */
    @Override
    public TeacherStudentTotalScoreResultDTO teacherTypeDetail(CourseTotalScoreTypeDetailQueryDTO dto) {

        TeacherStudentTotalScoreResultDTO result = new TeacherStudentTotalScoreResultDTO();

        // 获取总成绩设置内容
        CourseTotalScoreTypeQueryDTO typeQueryDTO = new CourseTotalScoreTypeQueryDTO();
        typeQueryDTO.setClassId(dto.getClassId());
        typeQueryDTO.setType(dto.getType());
        CourseTotalScoreTypeResultDTO typeResultDTO = findCourseTotalScoreType(typeQueryDTO);
        if (typeResultDTO == null) {
            result.setIsUserLevelShow(0);
        } else {
            result.setIsUserLevelShow(typeResultDTO.getIsUserLevelShow());
        }

        // 获取总成绩等级分制
        CourseTotalScoreConfigClassDTO configClassDTO = new CourseTotalScoreConfigClassDTO();
        configClassDTO.setClassId(dto.getClassId());
        configClassDTO.setType(dto.getType());
        List<CourseTotalScoreConfigResultDTO> configs = courseTotalScoreTypeConfigService.courseTotalScoreTypeConfig(configClassDTO);
        result.setTypeConfig(configs);

        // 考勤获取统计信息
        if (dto.getType().equals(CourseContentTypeEnum.COURSE_ATTENDANCE.getCode())) {
            CourseTotalScoreTypeQueryDTO attendanceQuery = new CourseTotalScoreTypeQueryDTO();
            attendanceQuery.setContentId(dto.getContentId());
            result.setAttendanceStat(courseTotalScoreMapper.teacherAttendanceTotalScoreTotal(attendanceQuery));
        }

        // 获取平均分
        typeQueryDTO.setContentId(dto.getContentId());
        typeQueryDTO.setSliceId(dto.getSliceId());
        List<TotalScoreStudentListDTO> list = courseTotalScoreMapper.teacherStudentTotalScoreList(typeQueryDTO);
        if (list != null && list.size() == 1) {
            result.setAvgScore(MathUtils.stripTrailingZeros(list.get(0).getStudentScore(), 1));
        } else {
            result.setAvgScore(new BigDecimal(0));
        }

        // 获取总成绩加权课程内容
        List<TotalScoreStudentListDTO> contentList = courseTotalScoreMapper.teacherStudentDetailScoreList(dto);
        if (Objects.nonNull(contentList)) {
            contentList.forEach(item -> {
                item.setStudentScore(MathUtils.stripTrailingZeros(item.getStudentScore(), 1));
                item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
                item.setIsUserLevelShow(result.getIsUserLevelShow());
                item.setGrade(checkTypeGrade(configs, item.getScore(), item.getStudentScore()));
                result.setAvgGrade(checkTypeGrade(configs, item.getScore(), result.getAvgScore()));
            });
            result.setList(contentList);
        } else {
            result.setAvgGrade(configs.get(configs.size() - 1).getGrade());
        }
        return result;

    }

    /**
     * 总成绩学生列表查询
     * <p>提示：老师未设置加权成绩 （1：未设置总成绩住信息；2：未设置加权成绩项）</p>
     * <p>提示：未公布成绩（IsShowStudent为1时公布 0不公布）</p>
     * <p>否显示加权成绩项: 0不显示 1显示</p>
     */
    @Override
    @DS("slaver")
    public TotalScoreStudentScoreDTO allStudentScore(CourseTotalScoreStudentQueryDTO dto) {

        TotalScoreStudentScoreDTO studentScore = new TotalScoreStudentScoreDTO();
        // 获取总成绩总配置
        LambdaQueryWrapper<CourseTotalScoreEntity> wrapper = Queries.lambda();
        wrapper.eq(CourseTotalScoreEntity::getClassId, dto.getClassId());
        CourseTotalScoreResultDTO resultDTO = courseTotalScoreMapper.selectDtoOne(wrapper, courseTotalScoreConvert::convert);
        if (resultDTO == null || resultDTO.getFullScore() == null) {
            return null;
        }
        studentScore.setFullScore(MathUtils.stripTrailingZeros(resultDTO.getFullScore(), 1));
        // 等级分制没有设置 默认为不开启 0 （0不开启 1开启）
        studentScore.setIsUserLevelShow(resultDTO.getIsUserLevelShow() == null ? 0 : resultDTO.getIsUserLevelShow());
        // 对学生是否显示加权成绩项 默认为开启 1 （0不开启 1开启）
        studentScore.setIsShowStudentRule(resultDTO.getIsShowStudentRule() == null ? 1 : resultDTO.getIsShowStudentRule());
        // 对学生是否显示总成绩 默认为开启 1 （0不开启 1开启）
        studentScore.setIsShowStudent(resultDTO.getIsShowStudent() == null ? 1 : resultDTO.getIsShowStudent());

        // 判断是否对学生显示成绩
        if (resultDTO.getIsShowStudent().equals(0)) {
            return studentScore;
        }

        // 获取总成绩最高分最低分平均分
        CourseTotalScoreAllScoreResultDTO allScoreResultDTO = courseTotalScoreContentSonMapper.findTotalScoreAllScoreInfo(dto.getClassId());
        if (allScoreResultDTO == null) {
            return null;
        }
        studentScore.setMaxScore(MathUtils.stripTrailingZeros(allScoreResultDTO.getMaxScore(), 1));
        studentScore.setMinScore(MathUtils.stripTrailingZeros(allScoreResultDTO.getMinScore(), 1));
        studentScore.setAvgScore(MathUtils.stripTrailingZeros(allScoreResultDTO.getAvgScore(), 1));

        // 获取总成绩等级分制
        CourseTotalScoreConfigClassDTO configClass = new CourseTotalScoreConfigClassDTO();
        configClass.setClassId(dto.getClassId());
        configClass.setType(TotalScoreTypeEnum.ALL_SCORE.getCode());
        List<CourseTotalScoreConfigResultDTO> configList = courseTotalScoreConfigService.findCourseTotalScoreConfig(configClass);
        studentScore.setConfigList(configList);

        // 设置等级分制
        studentScore.setFullGrade(checkTypeGrade(configList, studentScore.getFullScore(), studentScore.getFullScore()));
        studentScore.setMaxGrade(checkTypeGrade(configList, studentScore.getFullScore(), studentScore.getMaxScore()));
        studentScore.setMinGrade(checkTypeGrade(configList, studentScore.getFullScore(), studentScore.getMinScore()));
        studentScore.setAvgGrade(checkTypeGrade(configList, studentScore.getFullScore(), studentScore.getAvgScore()));

        // 获取各分类成绩结果
        CourseTotalScoreStudentQueryDTO queryDTO = new CourseTotalScoreStudentQueryDTO();
        queryDTO.setClassId(dto.getClassId());
        queryDTO.setStudentId(dto.getStudentId());
        List<TotalScoreStudentTypeInfoDTO> contentList = courseTotalScoreMapper.studentTypeTotalScore(queryDTO);

        // 没有设置成绩项直接返回空
        if (contentList == null || contentList.size() == 0) {
            return null;
        }

        //计算学生最终成绩和等级分制
        BigDecimal stuScore = contentList.stream().map(TotalScoreStudentTypeInfoDTO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
        studentScore.setStudentScore(MathUtils.stripTrailingZeros(stuScore, 1));
        studentScore.setGrade(checkTypeGrade(configList, resultDTO.getFullScore(), stuScore));

        // 判断是否显示学生成绩
        if (studentScore.getIsShowStudentRule().equals(1)) {
            // 查询子项加权成绩
            List<TotalScoreStudentTypeSonInfoDTO> sonList = courseTotalScoreMapper.studentTypeSonTotalScore(queryDTO);
            sonList.forEach(sItem -> {
                sItem.setWeight(MathUtils.stripTrailingZeros(sItem.getWeight(), 1));
                sItem.setScore(MathUtils.stripTrailingZeros(sItem.getStudentScore(), 1));
                sItem.setIsUserLevelShow(studentScore.getIsUserLevelShow());
                sItem.setStudentScore(MathUtils.stripTrailingZeros(sItem.getStudentScore(), 1));
                sItem.setGrade(checkTypeGrade(configList, studentScore.getFullScore(), sItem.getStudentScore()));
            });
            Map<String, List<TotalScoreStudentTypeSonInfoDTO>> map = sonList.stream().collect(Collectors.groupingBy(TotalScoreStudentTypeSonInfoDTO::getType));
            // 添加子成绩项
            contentList.forEach(item -> {
                item.setWeight(MathUtils.stripTrailingZeros(item.getWeight(), 1));
                item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
                item.setIsUserLevelShow(studentScore.getIsUserLevelShow());
                item.setGrade(checkTypeGrade(configList, studentScore.getFullScore(), item.getScore()));
                if (!Objects.equals(CourseContentTypeEnum.COURSE_ATTENDANCE.getCode(), item.getType())) {
                    if (map.containsKey(item.getType().toString())) {
                        item.setSonList(map.get(item.getType().toString()));
                    } else {
                        item.setSonList(new ArrayList<>());
                    }
                }
            });
            studentScore.setContentList(contentList);
        }
        return studentScore;
    }

    /**
     * 学生端各分类成绩查询
     */
    @Override
    public TotalScoreStudentTypeMsgDTO typeScore(CourseTotalScoreTypeQueryDTO dto) {

        //获取分类成绩总配置
        TotalScoreStudentTypeMsgDTO result = new TotalScoreStudentTypeMsgDTO();
        CourseTotalScoreTypeResultDTO typeResult = this.findCourseTotalScoreType(dto);

        if (typeResult == null) {
            typeResult = new CourseTotalScoreTypeResultDTO();
            typeResult.setType(dto.getType());
            typeResult.setClassId(dto.getClassId());
            typeResult.setIsUserLevelShow(0);
        }

        result.setType(typeResult);

        // 考勤非考勤 统计查询
        if (!dto.getType().equals(CourseContentTypeEnum.COURSE_ATTENDANCE.getCode())) {
            List<TotalScoreStudentTotalTipDTO> statList = courseTotalScoreMapper.studentTotalScoreTotal(dto);
            result.setStatList(statList);
        } else {
            List<TotalScoreStudentTotalTipDTO> statAttendanceList = courseTotalScoreMapper.studentAttendanceTotalScoreTotal(dto);
            result.setStatList(statAttendanceList);
        }

        // 学生各分类 记录列表
        List<TotalScoreStudentListDTO> contentList = courseTotalScoreMapper.studentTotalScoreList(dto);

        // 各分类等级分制查询
        CourseTotalScoreConfigClassDTO configClassDTO = new CourseTotalScoreConfigClassDTO();
        configClassDTO.setClassId(dto.getClassId());
        configClassDTO.setType(dto.getType());
        List<CourseTotalScoreConfigResultDTO> configList = courseTotalScoreTypeConfigService.courseTotalScoreTypeConfig(configClassDTO);
        result.setConfigList(configList);

        // 设置各个学生的等级分制等级
        CourseTotalScoreTypeResultDTO finalTypeResult = typeResult;
        contentList.forEach(item -> {
            item.setStudentScore(MathUtils.stripTrailingZeros(item.getStudentScore(), 1));
            item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
            item.setIsUserLevelShow(finalTypeResult.getIsUserLevelShow());
            item.setGrade(checkTypeGrade(configList, item.getScore(), item.getStudentScore()));
        });
        result.setContentList(contentList);
        return result;
    }

    /**
     * 学生端各分类成绩查询
     */
    @Override
    @DS("slaver")
    public PageInfo<TotalScoreStudentListDTO> typeScorePage(CourseTotalScoreTypeQueryDTO dto) {
        // 学生各分类 记录列表
        ClassStudentResultDTO mainStudent = R.as(classStudentClient.findVirtualClassStudentByClassIdAndUserId(dto.getClassId(), dto.getStudentId()));
        dto.setStudentId(mainStudent.getStudentId());
        PageInfo<TotalScoreStudentListDTO> contentList =
            Pages.convert(courseTotalScoreMapper.studentTotalScorePage(Pages.page(dto), dto));
        contentList.getRows().forEach(item -> {
            item.setStudentScore(MathUtils.stripTrailingZeros(item.getStudentScore(), 1));
            item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
        });
        return contentList;
    }

    /**
     * 校验等级值
     */
    private String checkTypeGrade(List<CourseTotalScoreConfigResultDTO> list, BigDecimal fullScore, BigDecimal studentScore) {
        String grade = "";
        fullScore = fullScore == null ? new BigDecimal(0) : fullScore;
        studentScore = studentScore == null ? new BigDecimal(0) : studentScore;
        for (int i = 0; i < list.size(); i++) {
            CourseTotalScoreConfigResultDTO item = list.get(i);
            BigDecimal maxScore = fullScore.multiply(new BigDecimal(item.getMax())).divide(new BigDecimal(100), BigDecimal.ROUND_DOWN);
            BigDecimal minScore = fullScore.multiply(new BigDecimal(item.getMin())).divide(new BigDecimal(100), BigDecimal.ROUND_DOWN);
            if (i == 0) {
                // 第一次判断 最高分要做小于等于判断 （比如 90-100分，要判断等于100分的数据）
                if (studentScore.compareTo(minScore) >= 0 && studentScore.compareTo(maxScore) <= 0) {
                    grade = item.getGrade();
                    return grade;
                }
            } else {
                // 第二次判断 ：比如 80到90的得分计算不能超过90分可疑等于80分
                if (studentScore.compareTo(minScore) >= 0 && studentScore.compareTo(maxScore) < 0) {
                    grade = item.getGrade();
                    return grade;
                }
            }
        }
        return grade;
    }

    /**
     * 分类成绩下载
     */
    @Override
    public void downExcel(CourseTotalScoreStudentQueryDTO dto, HttpServletResponse response) {

        CourseContentTotalScorePCResultDTO resultDTO = new CourseContentTotalScorePCResultDTO();

        // 查询分表表头信息
        List<CourseContentTotalTipDTO> tipList = courseTotalScoreStudentMapper.studentTypeScoreTitle(dto);
        tipList.forEach(item -> {
            item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
            item.setAvgScore(MathUtils.stripTrailingZeros(item.getAvgScore(), 1));
        });
        resultDTO.setTipList(tipList);

        // 学生得分行转列
        CourseTotalScoreStudentRowsQueryDTO rowsQueryDTO = new CourseTotalScoreStudentRowsQueryDTO();
        rowsQueryDTO.setClassId(dto.getClassId());
        rowsQueryDTO.setContentId(dto.getContentId());
        rowsQueryDTO.setType(dto.getType());
        rowsQueryDTO.setKeyWords(dto.getKeyWords());
        rowsQueryDTO.setGroupId(dto.getGroupId());
        rowsQueryDTO.setList(tipList);
        List<Map<String, Object>> studentList = courseTotalScoreStudentMapper.studentTypeScoreList(rowsQueryDTO);

        List<Map<String, Object>> titleList = tipList.stream().map(v -> {
            Map<String, Object> map = new LinkedHashMap<>();
            map.put("title", v.getName() + "(总分: " + v.getScore() + " 分)");
            map.put("unionValue", v.getUnionStudentScore());
            return map;
        }).collect(Collectors.toList());

        //考勤翻译字段
        if (dto.getType() == 10) {
            studentList.forEach(item -> {
                titleList.forEach(tItem -> {
                    String key = tItem.get("unionValue").toString();
                    item.put(key, attendanceValue(item.get(key).toString()));
                });
            });
        }

        String description = "成绩";
        if (dto.getType() == 1) {
            description = "互动课件答题成绩";
        }
        if (dto.getType() == 3) {
            description = "作业成绩";
        }
        if (dto.getType() == 4) {
            description = "测评成绩";
        }
        if (dto.getType() == 6) {
            description = "互动视频答题成绩";
        }
        if (dto.getType() == 10) {
            description = "考勤成绩";
        }

        ClassResultDTO classDto = classClient.findClass(dto.getClassId()).getData();
        CourseResultDTO courseDto = remoteCourseClient.findCourse(classDto.getCourseId()).getData();
        description = courseDto.getCourseName() + " " + classDto.getName() + " " + description;

        XSSFWorkbook workbook = ExcelUtil.createExcel("成绩管理", description, titleList, studentList);
        ExcelUtil.downLoadExcel("成绩管理", response, workbook);
    }

    private String attendanceValue(String value) {
        String name = "--";
        switch (value) {
            case "1":
                name = "出勤";
                break;
            case "2":
                name = "迟到";
                break;
            case "3":
                name = "旷课";
                break;
            case "4":
                name = "早退";
                break;
            case "5":
                name = "请假";
                break;
            default:
                break;
        }
        return name;
    }


    //======================功能变更V2======================================
    /**
     * 老师 分类成绩查询 分页
     */
    @Override
    @DS("slaver")
    public PageInfo<TotalScoreStudentListDTO> teacherTypeScorePageV2(CourseTotalScoreTypeQueryDTO dto) {
        PageInfo<TotalScoreStudentListDTO> page =
            Pages.convert(courseTotalScoreMapper.teacherStudentTotalScorePageV2(Pages.page(dto), dto));
        page.getRows().forEach(item -> {
            item.setAvgScore(MathUtils.stripTrailingZeros(item.getAvgScore(), 1));
            item.setScore(MathUtils.stripTrailingZeros(item.getScore(), 1));
        });
        return page;
    }
}
